namespace ImapComponent.Net.Mail.Imap4
{
    using System.Collections;

    /// <summary>
    /// Represents a collection of Mailboxes.
    /// </summary>
    public class MailboxCollection : CollectionBase
    {
        #region Methods

        /// <summary>
        /// Adds the provided mailbox to the collection.
        /// </summary>
        /// <param name="mailbox">The mailbox to be added.</param>
        public void Add(Mailbox mailbox)
        {
            this.List.Add(mailbox);
        }

        #endregion // Methods

        #region Indexers

        /// <summary>
        /// Returns the mailbox at the specified index in the collection.
        /// </summary>
        public Mailbox this[int index]
        {
            get
            {
                return (Mailbox)this.List[index];
            }
        }

        /// <summary>
        /// Returns the mailbox with the specified name in the collection.
        /// </summary>
        public Mailbox this[string mailboxName]
        {
            get
            {
                for (int i = 0; i < this.List.Count; i++)
                {
                    if (((Mailbox)this.List[i]).Name == mailboxName)
                    {
                        return this[i];
                    }
                }

                return null;
            }
        }

        #endregion // Indexers
    }
}